package com.mingke.chat.message.request;

import com.mingke.chat.message.EasyChatMessage;
import com.mingke.chat.message.EasyChatMessageType;

import java.nio.channels.AsynchronousSocketChannel;
import java.util.HashMap;
import java.util.Map;

/**
 * 易聊消息请求基类
 */
public abstract class EasyChatRequest extends EasyChatMessage {
    //用来存储类型编码和对应消息的Map
    private static Map<Byte, Class<?>> requestType = new HashMap<>();
    static {
        requestType.put(EasyChatMessageType.C2CRequest.getMessageCode(), EasyChatC2CRequest.class);
        requestType.put(EasyChatMessageType.ReportMessage.getMessageCode(), EasyChatReportInfo.class);
        requestType.put(EasyChatMessageType.GroupRequest.getMessageCode(), EasyChatGroupRequest.class);
    }
    /** 根据消息类型获取到消息class的静态方法*/
    public static Class<?> getRequestType(byte num) {
        return requestType.get(num);
    }

    /** 每个消息都必须要去实现的处理消息方法*/
    public abstract void handlerMessage(AsynchronousSocketChannel socketChannel);
}
